package com.mzj.saas.jobs.bill.repository;

import com.mzj.saas.jobs.bill.entity.EstateExpenseBill;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import javax.persistence.OrderBy;
import java.util.List;

public interface EstateExpenseBillRepository extends PagingAndSortingRepository<EstateExpenseBill, Long>, JpaSpecificationExecutor<EstateExpenseBill>, JpaRepository<EstateExpenseBill, Long> {

    List<EstateExpenseBill> findByHouseIdAndPaymentStatus(String houseId, Integer paymentStatus);

    List<EstateExpenseBill> findByIdIn(List<Long> ids);
    
    List<EstateExpenseBill> findByHouseId(String houseId);

    @OrderBy("create_time  asc")
    List<EstateExpenseBill> findByAuditStatusAndPaymentStatus(Integer auditStatus,Integer paymentStatus);

    @Query("select ee from EstateExpenseBill ee where ee.auditStatus = ?1 and  ee.paymentStatus in (?2,?3) order by ee.createTime desc")
    List<EstateExpenseBill> findByAuditStatusAndPaymentStatus(Integer auditStatus,Integer paymentStatus,Integer paymentStatus1);

    @Query("select ee from EstateExpenseBill ee where ee.auditStatus = ?1 and  ee.paymentStatus in (?2,2)  and  ee.houseId = ?3 order by ee.createTime asc")

    List<EstateExpenseBill> findByAuditStatusAndPaymentStatusAndHouseId(Integer auditStatus,Integer paymentStatus,String houseId);
    @Query("select ee from EstateExpenseBill ee where ee.auditStatus = ?1 and  ee.paymentStatus in (?2,2)  and  ee.houseId = ?3 and ee.orgId = ?4 order by ee.createTime asc")
    List<EstateExpenseBill> findByAuditStatusAndPaymentStatusAndHouseIdAndOrgId(Integer auditStatus,Integer paymentStatus,String houseId,Long orgId);

    @OrderBy("create_time  asc")
    List<EstateExpenseBill> findByRuleIdAndHouseIdAndChargeType(String ruleId,String houseId,Integer chargeType);
}
